/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VocSymbTest2;

/**
 *
 * @author StiggieBig
 */
public class Item implements Comparable<Item>{
    NonTerminal source;
    GrammarString stringBeforeDot;
    GrammarString stringAfterDot;
    
    Item(){
        source = new NonTerminal();
        stringBeforeDot = new GrammarString();
        stringAfterDot = new GrammarString();
    }
    
    //	constructor
    Item(NonTerminal newSource,
            GrammarString newStringBeforeDot,
            GrammarString newStringAfterDot) {
        source = new NonTerminal(newSource);
        stringBeforeDot = new GrammarString(newStringBeforeDot);
        stringAfterDot = new GrammarString(newStringAfterDot);
    }

    //  copy constructor
    Item(Item rhs){
        source = new NonTerminal(rhs.GetSource());
        stringBeforeDot = new GrammarString(rhs.GetStringBeforeDot());
        stringAfterDot = new GrammarString(rhs.GetStringAfterDot());
    }

    public NonTerminal GetSource() {
        return new NonTerminal(source);
    }

    public GrammarString GetStringBeforeDot() {
        return new GrammarString(stringBeforeDot);
    }

    public GrammarString GetStringAfterDot() {
        return new GrammarString(stringAfterDot);
    }
    
    public VocabularySymbol GetSymbAfterDot(){
    	return stringAfterDot.GetInitialSymb();
    }

    void Print() {
        source.Print();
        System.out.print("->");
        stringBeforeDot.Print();
        System.out.print(".");
        stringAfterDot.Print();
    }

    @Override
    public int compareTo(Item o) {
        int compVal = 0;
        compVal = source.compareTo(o.GetSource());
        if(compVal == 0){
            compVal = stringBeforeDot.compareTo(o.GetStringBeforeDot());
            if(compVal == 0){
            	compVal = stringAfterDot.compareTo(o.GetStringAfterDot());
            }
        }
        return compVal;
    }
}
